/**
 * @name drawSleep
 */
function drawSleep(id){
  var id="morning"
  var cvs = document.getElementById(id);
  var ctx = cvs.getContext("2d");
  ctx.strokeStyle = `#fff`;
  ctx.save()
  ctx.clearRect(0,0, cvs.width, cvs.height);
  var milliseconds=new Date().getMilliseconds()

  ctx.beginPath();
  drawCirl(ctx,{x:300,y:80},5,15,(milliseconds/1000)*2)
  ctx.stroke();

  window.requestAnimationFrame(drawSleep);
}
/**
 * @name 画图
 * @param {*} position //圆心
 * @param {*} length //间隔
 * @param {int} count //绘制次数
 * @param {int} angle // -0.5 ~ 0.5
 */
function drawCirl(ctx,position,length,count,angle){
  var x=position?(position.x||300):300
  var y=position?(position.y||100):100
  var length=length||10
  var count=count||5
  var angle=angle||0
  // if(angle>0.5||angle<-0.5)throw new Error("angle的范围-0.5~0.5")
  ctx.moveTo(x,y)
  for(let i=0;i<count;i++){
    var order=i%2==0
    var randomAngle=angle
    var angle1=randomAngle*Math.PI
    var angle2=(1+randomAngle)*Math.PI
    ctx.arc(x,y,length*i,order?angle1:angle2,order?angle2:angle1,false);
  }
}

/**
 * @name drawMorning 
 */
function drawMorning(){
  

}

/**
 * @name drawWords 使用cavas打字
 */
function drawWords(text){
  var id="morning"
  var cvs = document.getElementById(id);
  var ctx = cvs.getContext("2d");
  ctx.save()
  ctx.clearRect(0,0, cvs.width, cvs.height);
  ctx.font="14px Arial";
  ctx.fillStyle = '#fff';
  ctx.fillText(text,20,30)
}



export {drawSleep,drawMorning,drawWords}